package net.huashitong.node.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.filter.BaseFilter;
import com.sirdc.modules.utils.CollectionsUtils;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.entity.NewProjects;
import net.huashitong.Project.filter.NewProjectsFilter;
import net.huashitong.node.entity.NodeNewschedules;
import net.huashitong.node.filter.NodeNewschedulesFilter;
import net.huashitong.oversee.databean.PlanStartScheduleDto;
import net.huashitong.user.entity.BnpUser;
import net.huashitong.user.filter.BnpUserFilter;
import net.huashitong.user.filter.OnlineFilter;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

import static net.huashitong.utils.UtilsTools.getCurrentDateTime1;

@Repository
public class NodeNewschedulesDao extends StringDao<NodeNewschedules> {

    /**
     * 根据经办人查下数据
     *
     * @param filter
     * @return
     */
    public List<NodeNewschedules> queryListByNameAndPhone(BnpUserFilter filter) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.operatorUser = :operatorUser ").setParam("operatorUser", filter.getName());
        query.append(" and obj.operatorPhone = :operatorPhone order By obj.nodeId desc ").setParam("operatorPhone", filter.getPhone());
        return query.listResult();
    }


    /**
     * 根据经办人名字手机号查询节点清单
     *
     * @param phone
     * @param name
     * @return
     */
    public List<NodeNewschedules> queryOperator(String phone, String name) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.operatorUser = :operatorUser ").setParam("operatorUser", name);
        query.append(" and obj.operatorPhone = :operatorPhone order By obj.nodeId desc ").setParam("operatorPhone", phone);
        return query.listResult();
    }

    /**
     * 根据责任人名字手机号查询节点清单
     *
     * @param phone
     * @param name
     * @return
     */
    public List<NodeNewschedules> queryResUser(String phone, String name) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.resUser = :resUser ").setParam("resUser", name);
        query.append(" and obj.resUserPhone = :resUserPhone order By obj.nodeId desc ").setParam("resUserPhone", phone);
        return query.listResult();
    }


    /**
     * 根据负责人查询去重的项目ID
     *
     * @param bnpUserFilter
     * @return projectIds
     */
    public List<String> getProjectIdByResUserAndDept(BnpUserFilter bnpUserFilter) {
        String sql = "SELECT DISTINCT project_id FROM t_bnp_node_newschedule b WHERE b.operator_user = ? AND b.res_dept = ?";
        Session session = sessionFactory.openSession();
        Query query = session.createSQLQuery(sql);
        query.setParameter(0, bnpUserFilter.getName());
        query.setParameter(1, bnpUserFilter.getBranch());
        List<String> projectIds;
        projectIds = query.list();
        return projectIds;
    }

    /**
     * 根据项目ID、节点ID查出任务节点
     *
     * @param projectId
     * @param nodeId
     * @return nodeList
     */
    public List<NodeNewschedules> getNodeNewschedulesByProjectId(String projectId, String nodeId) {
        Session session = sessionFactory.openSession();
        Query query;
        String sql = "SELECT b.operator_user operatorUser,b.status, b.node_filter nodeFilter, a.name projectId," +
                "b.node_id nodeId,b.node_name nodeName,b.fact_finish_date factFinishDate,b.sys_id sysId " +
                "FROM (SELECT * FROM t_bnp_new_project WHERE sys_id = ?) a ,t_bnp_node_newschedule b " +
                "WHERE a.sys_id = b.project_id AND b.node_id LIKE ? AND b.type = '2' ORDER BY node_id+0";
        query = session.createSQLQuery(sql);
        query.setParameter(0, projectId);
        query.setParameter(1, nodeId + ".%");
        query.setResultTransformer(Transformers.aliasToBean(NodeNewschedules.class));
        List<NodeNewschedules> nodeList = (List<NodeNewschedules>) query.list();
        return nodeList;
    }

    public List<NodeNewschedules> queryListByProjectId(String projectId, String type, String resDept, String state, String operatorUser) {
        GenericQuery query = createQuery("obj");
        if (ObjectUtils.isNotBlank(state)) {
            query.append(" and obj.state= :state ").setParam("state", state);
        }
        if (ObjectUtils.isNotBlank(resDept)) {
            query.append(" and obj.resDept like:resDept ").setParam("resDept", "%" + resDept + "%");
        }
        if (ObjectUtils.isNotBlank(operatorUser)) {
            query.append(" and obj.operatorUser =:operatorUser").setParam("operatorUser", operatorUser);
        }
//        query.append(" and obj.type= :type ").setParam("type", type);
        if ("2".equals(type)) {
            query.append(" and obj.projectId =:projectId order By obj.nodeId+0 desc ").setParam("projectId", projectId);
        } else {
            query.append(" and obj.projectId =:projectId order By obj.nodeId+0 asc ").setParam("projectId", projectId);
        }

        return query.listResult();
    }

    /**
     * 根据项目id返回项目节点，根据nodeId升序排序
     *
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getNodeByProjectId(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId order By obj.nodeId+0 asc ").setParam("projectId", projectId);
        return query.listResult();
    }

    /**
     * 部门不需要的不显示
     *
     * @param projectId
     * @param state
     * @return
     */
    public List<NodeNewschedules> getNodeByProjectIdAndState(String projectId, String state) {
        GenericQuery query = createQuery("obj");
        // 不等于
        if (ObjectUtils.isNotBlank(state)) {
            query.append(" and obj.state !=:state").setParam("state", state);
        }
        query.append(" and obj.projectId =:projectId order By obj.nodeId+0").setParam("projectId", projectId);
        return query.listResult();
    }

    public NodeNewschedules getNodeNewschedulesByProjectIdAndNodeId(String projectId, String nodeId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId ").setParam("projectId", projectId);
        query.append(" and obj.nodeId =:nodeId ").setParam("nodeId", nodeId);
        return query.firstResult();
    }

    public List<NodeNewschedules> getNodePlanTime(String projectId, String num) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId ").setParam("projectId", projectId);
        if ("0".equals(num)) {
            query.append(" and obj.resUser is null");
            query.append(" and obj.operatorUser is null");
            query.append(" and obj.type =:type").setParam("type", "2");
        } else if ("1".equals(num)) {
            query.append(" and obj.resUser is not null");
            query.append(" and obj.resUser !=:resUser").setParam("resUser", "");
            query.append(" and obj.operatorUser is not null");
            query.append(" and obj.operatorUser !=:operatorUser").setParam("operatorUser", "");
        }
        query.append(" and obj.state =:state").setParam("state", "0");
        return query.listResult();
    }

    public List<NodeNewschedules> getNodeIdsList(String nodeIds, String projectId, String state) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId ").setParam("projectId", projectId);
        query.append(" and obj.nodeIds =:nodeIds ").setParam("nodeIds", nodeIds);
        if (ObjectUtils.isNotBlank(state)) {
            query.append(" and obj.state =:state").setParam("state", state);
        } else {
            query.append(" and obj.state =:state").setParam("state", "1");
        }
        return query.listResult();
    }

    public List<NodeNewschedules> getNodeIdsLists(String nodeIds, String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId ").setParam("projectId", projectId);
        query.append(" and obj.nodeIds =:nodeIds ").setParam("nodeIds", nodeIds);
        return query.listResult();
    }

    public List<NodeNewschedules> getNodesBeforeCurrentNode(String nodeIds, String projectId, String nodeId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId ").setParam("projectId", projectId);
        query.append(" and obj.nodeIds =:nodeIds ").setParam("nodeIds", nodeIds);
        query.append(" and obj.state =:state").setParam("state", "1");
        query.append(" and node_id <= " + nodeId + "");
        query.append(" ORDER BY obj.nodeId+0 asc");
        return query.listResult();
    }

    public List<NodeNewschedules> getNodeIds(String nodeIds, String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId ").setParam("projectId", projectId);
        query.append(" and obj.nodeIds =:nodeIds ").setParam("nodeIds", nodeIds);
        //确定需要的节点
        query.append(" and obj.state =:state ").setParam("state", "1");
        query.append(" ORDER BY obj.nodeId+0");
        return query.listResult();
    }

    /**
     * 节点完成，并且属于需要的节点
     *
     * @param nodeIds
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getListNodeIds(String nodeIds, String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId ").setParam("projectId", projectId);
        query.append(" and obj.nodeIds =:nodeIds ").setParam("nodeIds", nodeIds);
        query.append(" and obj.status =:status ").setParam("status", "2");
        query.append(" and obj.state =:state ").setParam("state", "1");
        return query.listResult();
    }

    /**
     * 获取项目的第一个小节点(#标志)
     *
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getFirstNode1(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state =:state").setParam("state", "1");                 // 确定需要
        query.append(" and obj.type =:type").setParam("type", "1");                     // 大节点
        query.append(" and obj.preNodeId =:preNodeId").setParam("preNodeId", "#");           // 前置节点为#
        query.append(" and obj.status =:status").setParam("status", "0");                 // 状态为未开始
        query.append(" ORDER BY obj.nodeId+0");
        return query.listResult();
    }


    /**
     * 获取项目的第一批小节点(非#标志)
     *
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getFirstNode2(String projectId) {

        GenericQuery query1 = createQuery("obj");
        query1.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query1.append(" and obj.state =:state").setParam("state", "1");                 // 确定需要
        query1.append(" and obj.type =:type").setParam("type", "1");                     // 大节点
        query1.append(" and obj.status !=:status").setParam("status", "2");                // 状态为不能已完成
        query1.append(" ORDER BY obj.nodeId+0");
        List<NodeNewschedules> list1 = query1.listResult();

        GenericQuery query2 = createQuery("obj");
        query2.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query2.append(" and obj.state =:state").setParam("state", "1");                 // 确定需要
        query2.append(" and obj.type =:type").setParam("type", "1");                     // 大节点
        query2.append(" and obj.status =:status").setParam("status", "0");                // 状态为未完成
        query2.append(" ORDER BY obj.nodeId+0");
        List<NodeNewschedules> list2 = query2.listResult();

        List<String> nodeIds = new ArrayList<>();
        for (NodeNewschedules nodeNewschedules : list1) {
            nodeIds.add(nodeNewschedules.getNodeId());
        }
        List<NodeNewschedules> result = getOpen(list2, nodeIds);
        return result;
    }

    public NodeNewschedules getFirstNode3(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state !=:state").setParam("state", "1");                 // 确定需要
        query.append(" and obj.type =:type").setParam("type", "1");                     // 大节点
        query.append(" and obj.status =:status").setParam("status", "0");                // 状态为未完成
        query.append(" ORDER BY obj.nodeId+0 asc");
        return query.firstResult();
    }

    public List<NodeNewschedules> getFirstNode4(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state =:state").setParam("state", "1");                 // 确定需要
        query.append(" and obj.type =:type").setParam("type", "1");                     // 大节点
        query.append(" ORDER BY obj.nodeId+0");
        List<NodeNewschedules> list = query.listResult();

        List<String> nodeIds = new ArrayList<>();
        for (NodeNewschedules nodeNewschedules : list) {
            nodeIds.add(nodeNewschedules.getNodeId());
        }
        List<NodeNewschedules> result = getOpen(list, nodeIds);
        return result;
    }

    public List<NodeNewschedules> getOpen(List<NodeNewschedules> list2, List<String> nodeIds) {
        List<NodeNewschedules> result = new ArrayList<>();
        for (NodeNewschedules nodeNewschedules : list2) {
            String preNode = nodeNewschedules.getPreNodeId();
            if (preNode.contains(",")) {
                int i = 0;
                String[] arr = preNode.split(",");
                for (String s : arr) {
                    if (!nodeIds.contains(s)) {
                        i++;
                    }
                }
                //判断多所有前置节点都没有，才开启本节点
                if (i == arr.length) {
                    result.add(nodeNewschedules);
                }
            } else {
                if (!nodeIds.contains(preNode)) {
                    result.add(nodeNewschedules);
                }
            }
        }
        return result;
    }

    //判断项目是否有进行中的节点
    public boolean queryStartFlag(String projectId) {
        GenericQuery query1 = createQuery("obj");
        query1.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query1.append(" and obj.state =:state").setParam("state", "1");                 // 确定需要
        query1.append(" and obj.type =:type").setParam("type", "1");                     // 大节点
        query1.append(" and obj.status =:status").setParam("status", "1");                 // 状态为进行中
        query1.append(" ORDER BY obj.nodeId+0");
        List<NodeNewschedules> list1 = query1.listResult();
        int n1 = list1.size();
        GenericQuery query2 = createQuery("obj");
        query2.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query2.append(" and obj.state =:state").setParam("state", "1");                 // 确定需要
        query2.append(" and obj.type =:type").setParam("type", "2");                     // 小节点
        query2.append(" and obj.status =:status").setParam("status", "1");                 // 状态为进行中
        query2.append(" ORDER BY obj.nodeId+0");
        List<NodeNewschedules> list2 = query2.listResult();
        for (NodeNewschedules nodeNewschedules : list2) {
            for (NodeNewschedules newschedules : list1) {
                if (newschedules.getNodeId().equals(nodeNewschedules.getNodeIds())) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 获取项目名和节点
     *
     * @return
     */
    public List<NodeNewschedules> getNodeAndProjectName(String projectId, BnpUser bnpUser) {
        StringBuffer sql = new StringBuffer("");
        sql.append(" SELECT b.sys_id sysId, a. NAME projectId,b.node_id nodeId,b.node_name nodeName,b.fact_finish_date factFinishDate FROM");
        sql.append(" (SELECT * FROM t_bnp_new_project WHERE sys_id = '" + projectId + "')a,");
        sql.append(" t_bnp_node_newschedule b WHERE 1=1");
        sql.append(" and a.sys_id = b.project_id");
        if ("1".equals(bnpUser.getBranchType())) {
            sql.append(" and b.res_user = '" + bnpUser.getName() + "'");
            sql.append(" and b.res_dept = '" + bnpUser.getBranch() + "'");
        }
        if ("0".equals(bnpUser.getBranchType())) {
            sql.append(" and b.operator_user = '" + bnpUser.getName() + "'");
            sql.append(" and (b.status != '2' or b.status is null)");
        }

        sql.append(" order by node_id+0");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NodeNewschedules.class));
        List<NodeNewschedules> list = query.list();
        return list;
    }


    public List<NodeNewschedules> getNodeByUser(BnpUser bnpUser) {
        GenericQuery query = createQuery("obj");
        if ("1".equals(bnpUser.getBranchType())) {
            query.append(" and obj.resUser = '" + bnpUser.getName() + "'");
            query.append(" and obj.resDept = '" + bnpUser.getBranch() + "'");
        }
        if ("0".equals(bnpUser.getBranchType())) {
            query.append(" and obj.operatorUser = '" + bnpUser.getName() + "'");
            query.append(" and obj.operatorPhone = '" + bnpUser.getPhone() + "'");
            query.append(" and obj.type = '2'");
//            query.append(" and (obj.status != '2' or obj.status is null)");
        }
        query.append(" and obj.state = '1'");
        query.append(" order by node_id+0");
        return query.listResult();
    }


    /**
     * 根据系统id获取
     *
     * @param sysId
     * @return
     */
    public NodeNewschedules getNodeOne(String sysId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.sysId =:sysId").setParam("sysId", sysId);
        return query.singleResult();
    }

    /**
     * 查询部门管理的大节点
     *
     * @param projectId
     * @param
     * @return
     */
    public List<NodeNewschedules> getBigNode(String projectId, BnpUserFilter bnpUserFilter) {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(projectId)) {
            query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        }
        query.append(" and obj.operatorUser =:operatorUser").setParam("operatorUser", bnpUserFilter.getName());
        query.append(" and obj.resDept =:resDept").setParam("resDept", bnpUserFilter.getBranch());
        query.append(" and obj.state !=:state").setParam("state", "2");
        query.append(" and obj.type =:type").setParam("type", "1");
        return query.listResult();
    }

    /**
     * 查询某个项目某个大节点下的所有小节点
     *
     * @param nodeId
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getNode2(String nodeId, String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.nodeIds =:nodeIds").setParam("nodeIds", nodeId);
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state !=:state").setParam("state", "2");
        query.append(" and obj.type =:type").setParam("type", "2");
        query.append(" ORDER BY node_id+0");
        return query.listResult();
    }

    public List<NodeNewschedules> getNode3(String nodeId, String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.nodeId =:nodeId").setParam("nodeId", nodeId);
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" ORDER BY node_id+0");
        return query.listResult();
    }

    public NodeNewschedules getNode4(String nodeId, String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.nodeIds =:nodeIds").setParam("nodeIds", nodeId);
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state =:state").setParam("state", "1");              //确认需要
        query.append(" and obj.type =:type").setParam("type", "2");                 //小节点
        query.append(" ORDER BY node_id+0 asc");
        return query.firstResult();
    }

    public List<NodeNewschedules> getByResDeptAndOperatorUser(
            String projectsId,
            String resDept,
            String operatorUser,
            String state) {
        //缓存
//        String hql = "FROM NodeNewschedules n WHERE n.resDept=? and n.operatorUser=? and n.type=?";
//        if(StringUtils.isNotBlank(projectsId)){
//            hql += "and n.projectsId = '"+projectsId+"'";
//        }
//        if("1".equals(state)){
//            hql += "and n.state >= '"+state+"'";
//        }
//        Query query = getSession().createQuery(hql).setCacheable(true);
//        query.setParameter(0,resDept);
//        query.setParameter(1,operatorUser);
//        query.setParameter(2,"2");
//        List<NodeNewschedules> list = query.list();
//        return list;

        //无缓存
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(projectsId)) {
            query.append(" and obj.projectId =:projectId").setParam("projectId", projectsId);
        }
        query.append(" and obj.resDept =:resDept").setParam("resDept", resDept);
        query.append(" and obj.operatorUser =:operatorUser").setParam("operatorUser", operatorUser);
        if ("1".equals(state)) {
            query.append(" and obj.state >=:state").setParam("state", state);
        }
        return query.listResult();
    }

    public List<NodeNewschedules> getNodelistByNodeId(String nodeIds, String projectId, String nextId) {
//        GenericQuery query = createQuery("obj");
//        query.append(" and obj.nodeId like:nodeId").setParam("nodeId",nodeId+".%");
//        query.append(" and obj.nodeId >:nodeId").setParam("nodeId",nextId);
////        query.append(" and obj.type =:type").setParam("type",type);
//        query.append(" and obj.projectId =:projectId").setParam("projectId",projectId);
//        query.append(" ORDER BY node_id+0");
//        return query.listResult();

        StringBuffer sql = new StringBuffer("");
        sql.append(" SELECT sys_id sysId,operator_phone operatorPhone  ,fact_time factTime,node_type nodeType,operator_user operatorUser,plan_begin_date planBeginDate,plan_time planTime,pre_node_id preNodeId,res_dept resDept,res_user resUser,res_user_phone resUserPhone, status ,type,project_id projectId,node_id nodeId,node_ids nodeIds,state,node_filter nodeFilter,deny_reason denyReason,  node_name nodeName,fact_finish_date factFinishDate,is_delay isDelay ");
        sql.append(" FROM t_bnp_node_newschedule WHERE 1=1 and state=1 and");
        sql.append(" node_id LIKE '" + nodeIds + ".%' AND node_id > '" + nextId + "'  AND project_id = '" + projectId + "'");
        sql.append(" ORDER BY node_id+0");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NodeNewschedules.class));
        List<NodeNewschedules> list = query.list();
        return list;
    }

    public NodeNewschedules getNnsByProjectIdAndNodeId(String projectId, String nodeId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.nodeId =:nodeId").setParam("nodeId", nodeId);
        return query.firstResult();
    }

    public NodeNewschedules getBigNodesState(String projectId, String nodeId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.nodeId =:nodeId").setParam("nodeId", nodeId);
        query.append(" and obj.state =:state").setParam("state", "1");
        return query.firstResult();
    }

    public List<NodeNewschedules> getListByPreNodeId(String projectId, String preNodeId) {
        StringBuffer sql = new StringBuffer("");
        sql.append("SELECT sys_id sysId from t_bnp_node_newschedule where");
        sql.append("  FIND_IN_SET('" + preNodeId + "',pre_node_id) and project_id='" + projectId + "' and type=1");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NodeNewschedules.class));
        List<NodeNewschedules> list = (List<NodeNewschedules>) query.list();
        return list;
    }

    public List<NodeNewschedules> getListByPreNodeId2(String nodeId, String projectId) {
        StringBuffer sql = new StringBuffer("");
        sql.append("SELECT sys_id sysId,status status from t_bnp_node_newschedule where");
        sql.append(" node_id in(" + nodeId + ") and project_id='" + projectId + "' and type=1 and state=1 ORDER BY node_id+0");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NodeNewschedules.class));
        List<NodeNewschedules> list = (List<NodeNewschedules>) query.list();
        return list;
    }

    /**
     * 查询某project完成节点完成情况
     *
     * @param projectId
     * @param status
     * @return
     */
    public List<NodeNewschedules> getNodeByProjectIdAndStatus(String projectId, String status) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        if (ObjectUtils.isNotBlank(status)) {
            query.append(" and obj.status =:status").setParam("status", status);
        }
        return query.listResult();
    }

    /**
     * 查询某project 完成的所有小节点
     *
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getNode2ByProjectIdAndStatus(String projectId, String status) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.type =:type").setParam("type", "2"); //选中小节点
        if (ObjectUtils.isNotBlank(status)) {
            query.append(" and obj.status =:status").setParam("status", status);
        }
        return query.listResult();
    }

    public List<NodeNewschedules> getNodeInfo(String projectId, //任务状态      0未开始 1已开始 2结束
                                              String type,      //节点类型      1大节点 2小节点
                                              String status,    //节点确定状态   0未确定 1已确定 2不需要
                                              String state
    ) {
        GenericQuery query = createQuery("obj");
        if (ObjectUtils.isNotBlank(projectId)) {
            query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        }
        if (ObjectUtils.isNotBlank(type)) {
            query.append(" and obj.type =:type").setParam("type", type);
        }
        if (ObjectUtils.isNotBlank(status)) {
            query.append(" and obj.status =:status").setParam("status", status);
        }
        if (ObjectUtils.isNotBlank(state)) {
            query.append(" and obj.state =:state").setParam("state", state);
        }
        query.append(" order By CAST(obj.nodeId as int) asc  ");
        return query.listResult();
    }

    /**
     * 查询某project 的所有小节点(null)、or已完成(2)、or已开始(1)的数量
     *
     * @param projectId
     * @return
     */
    public int getNodeCompletionOrNotNum(String projectId, String status) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        //1为部门需要的节点
        query.append(" and obj.state =:state").setParam("state", "1");
        //选中小节点
        query.append(" and obj.type =:type").setParam("type", "2");
        if (ObjectUtils.isNotBlank(status)) {
            query.append(" and obj.status =:status").setParam("status", status);
        }
        return query.count();
    }

    /**
     * 查询某部门的所有小节点(null)、or已完成(2)、or已开始(1)的数量
     *
     * @param resDept
     * @param status
     * @return
     */
    public int getNodeCompletionOrNotNumByDept(String resDept, String status) {
        GenericQuery query = createQuery("obj");
        //选中小节点
        query.append(" and obj.type =:type").setParam("type", "2");
        if (ObjectUtils.isNotBlank(resDept)) {
            query.append(" and obj.resDept =:resDept").setParam("resDept", resDept);
        } else {
            query.append(" and res_dept not in('永泰县自然资源和规划局', '永泰县住房和城乡建设局', '永泰县发展改革局', '永泰县生态环境局'," +
                    "'永泰县水利局', '永泰县林业局', '永泰县财政局', '气象局', '永泰县公安消防大队', '永泰县人民防空办公室', '永泰县人力资源和社会保障局')");
        }
        if (ObjectUtils.isNotBlank(status)) {
            query.append(" and obj.status =:status").setParam("status", status);
        }
        query.append(" and obj.state =:state").setParam("state", "1");
        return query.count();
    }

    /**
     * 通过项目id获取部门需要的大节点
     *
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getNeedBigNodeByProjectId(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.type =:type").setParam("type", "1");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state =:state").setParam("state", "1");
        query.append(" ORDER BY obj.nodeId+0");
        return query.listResult();
    }

    /**
     * 通过项目id获取部门需要的小节点
     *
     * @param projectId
     * @return
     */
    public List<NodeNewschedules> getNeedSmallNodeByProjectId(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.type =:type").setParam("type", "2");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state =:state").setParam("state", "1");
        query.append(" ORDER BY obj.nodeId+0");
        return query.listResult();
    }


    /**
     * 获取小节点开始的数据
     *
     * @return
     */
    public List<NodeNewschedules> getListByType() {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.type =:type").setParam("type", "2");
        query.append(" and obj.status =:status").setParam("status", "1");
        query.append(" and obj.state =:state").setParam("state", "1");
        return query.listResult();
    }

    //获取所有部门
    public List<NodeNewschedules> getAllDeptByProId() {
        StringBuffer sql = new StringBuffer("");
        sql.append("SELECT res_dept resDept from t_bnp_node_newschedule group by res_dept");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NodeNewschedules.class));
        List<NodeNewschedules> list = (List<NodeNewschedules>) query.list();
        return list;
    }

    //获取未完成小节点
    public List<NodeNewschedules> getNoFinishNode(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and status <> '2' and type = '2'");
        query.append(" and obj.state =:state").setParam("state", "1");
        query.setOrder("nodeId+0", BaseFilter.ASC);
        return query.listResult();
    }

    /**
     * 查询未确定节点列表
     *
     * @return
     */
    public List<NodeNewschedules> getNodeState() {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.state =:state").setParam("state", "0");
        return query.listResult();
    }

    /**
     * 查询进行中节点
     *
     * @return
     */
    public List<NodeNewschedules> getNodeStateAndStatus() {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.status =:status").setParam("status", "1");
        query.append(" and obj.state =:state").setParam("state", "1");
        return query.listResult();
    }

    /**
     * 查询进行中节点
     *
     * @return
     */
    public List<NodeNewschedules> getNodeStateAndStatusByProjectId(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.status =:status").setParam("status", "1");
        query.append(" and obj.state =:state").setParam("state", "1");
        return query.listResult();
    }

    /**
     * 查询任务总数（进行中）
     *
     * @param filter
     * @return
     */
    public List<NodeNewschedules> queryListByFilterZong(NodeNewschedulesFilter filter) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.status = :status").setParam("status", "1");
        query.append(" and obj.state = :state").setParam("state", "1");
        query.append(" and obj.type = :type").setParam("type", "2");
        query.append(" and obj.operatorPhone = :operatorPhone order By obj.nodeId desc ").setParam("operatorPhone", filter.getOperatorPhone());
        return query.listResult();
    }

    /**
     * 查询任务列表(审批部门，节点进行中)
     *
     * @param filter
     * @return
     */
    public List<NodeNewschedules> queryListByFilterList(NodeNewschedulesFilter filter) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.status = :status").setParam("status", "1");
        query.append(" and obj.state = :state").setParam("state", "1");
        query.append(" and obj.type = :type").setParam("type", "2");
        query.append(" and obj.operatorPhone = :operatorPhone order By obj.projectId desc ").setParam("operatorPhone", filter.getOperatorPhone());
        return query.listResult(filter);
    }

    /**
     * 查询任务列表(审批部门，节点已完成)
     *
     * @param filter
     * @return
     */
    public List<NodeNewschedules> queryFinishedSmallNodesByOperatorPhone(NodeNewschedulesFilter filter) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.status = :status").setParam("status", "2");
        query.append(" and obj.state = :state").setParam("state", "1");
        query.append(" and obj.type = :type").setParam("type", "2");
        query.append(" and obj.operatorPhone = :operatorPhone order By obj.projectId desc ").setParam("operatorPhone", filter.getOperatorPhone());
        return query.listResult(filter);
    }

    /**
     * 查询任务列表(审批部门，节点未完成)
     *
     * @param filter
     * @return
     */
    public List<NodeNewschedules> queryNoFinishedSmallNodesByOperatorPhone(NodeNewschedulesFilter filter) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.status = :status").setParam("status", "0");
        query.append(" and obj.state = :state").setParam("state", "1");
        query.append(" and obj.type = :type").setParam("type", "2");
        query.append(" and obj.operatorPhone = :operatorPhone order By obj.projectId desc ").setParam("operatorPhone", filter.getOperatorPhone());
        return query.listResult(filter);
    }

    /**
     * 查询任务列表(审批部门，节点)
     *
     * @param filter
     * @return
     */
    public List<NodeNewschedules> querySmallNodesByOperatorPhone(NodeNewschedulesFilter filter) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.state = :state").setParam("state", "1");
        query.append(" and obj.type = :type").setParam("type", "2");
        query.append(" and obj.operatorPhone = :operatorPhone order By obj.projectId desc ").setParam("operatorPhone", filter.getOperatorPhone());
        return query.listResult(filter);
    }

    /**
     * 未开始的大节点
     *
     * @return
     */
    public List<NodeNewschedules> queryList() {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.type= :type").setParam("type", "1");
        query.append(" and obj.state= :state").setParam("state", "1");
        query.append(" and obj.status = :status").setParam("status", "0");
        return query.listResult();
    }

    public List<NodeNewschedules> queryByFilter(NodeNewschedulesFilter filter) {
        GenericQuery query = createQuery("obj");
        if (ObjectUtils.isNotBlank(filter.getType())) {
            query.append(" and obj.type =:type").setParam("type", filter.getType());
        }
        if (ObjectUtils.isNotBlank(filter.getState())) {
            query.append(" and obj.state =:state").setParam("state", filter.getState());
        }
        if (ObjectUtils.isNotBlank(filter.getStatus())) {
            query.append(" and obj.status =:status").setParam("status", filter.getStatus());
        }
        if (ObjectUtils.isNotBlank(filter.getResDept())) {
            query.append(" and obj.resDept like:resDept").setParam("resDept",
                    StringUtils.getLikewords(filter.getResDept()));
        }
        if (ObjectUtils.isNotBlank(filter.getResUser())) {
            query.append(" and obj.resUser like:resUser").setParam("resUser",
                    StringUtils.getLikewords(filter.getResUser()));
        }
        if (ObjectUtils.isNotBlank(filter.getOperatorUser())) {
            query.append(" and obj.operatorUser like:operatorUser").setParam("operatorUser",
                    StringUtils.getLikewords(filter.getOperatorUser()));
        }
        if (ObjectUtils.isNotBlank(filter.getNodeId())) {
            query.append(" and obj.nodeId =:nodeId").setParam("nodeId", filter.getNodeId());
        }
        if (ObjectUtils.isNotBlank(filter.getNodeIds())) {
            query.append(" and obj.nodeIds =:nodeIds").setParam("nodeIds", filter.getNodeIds());
        }
        if (ObjectUtils.isNotBlank(filter.getNodeName())) {
            query.append(" and obj.nodeName like:nodeName").setParam("nodeName",
                    StringUtils.getLikewords(filter.getNodeName()));
        }
        if (ObjectUtils.isNotBlank(filter.getNodeType())) {
            query.append(" and obj.nodeType =:nodeType").setParam("nodeType", filter.getNodeType());
        }
        if (ObjectUtils.isNotBlank(filter.getProjectId())) {
            query.append(" and obj.projectId =:projectId").setParam("projectId", filter.getProjectId());
        }
        if (ObjectUtils.isNotBlank(filter.getFactFinishDate())) {
            query.append(" and obj.factFinishDate >:factFinishDate").setParam("factFinishDate", filter.getFactFinishDate());
        }
        if (CollectionsUtils.isNotEmpty(filter.getProjectIds())) {
            query.append(" and obj.projectId in (:projectIds)");
            query.setParamList("projectIds", filter.getProjectIds());
        }
        return query.listResult(filter);
    }


    public int getDataCount() {
        GenericQuery query = createQuery("obj");
        return query.count();
    }

    public BigInteger queryProgressNodesCountByFilter(OnlineFilter filter) {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT count(*) from t_bnp_node_newschedule where");
        //status = '1' and 小节点
        sql.append(" type = '2' ");
        if (StringUtils.isNotBlank(filter.getName())) {
            sql.append(" and (operator_user = '" + filter.getName() + "' or res_user = '" + filter.getName() + "')");
        }
        //如果结束时间已经设置（结束时间必须设置）
        if (StringUtils.isNotBlank(filter.getEndDate())) {
            sql.append(" and unix_timestamp( plan_begin_date ) between unix_timestamp( '" + filter.getStartDate() + "') and unix_timestamp( '" + filter.getEndDate() + "' )");
            sql.append("or ((operator_user = '" + filter.getName() + "' or res_user = '" + filter.getName() + "') and status = '1' and type = '2' and state = '1')");
        } else {
            sql.append(" and unix_timestamp( plan_begin_date ) between unix_timestamp( '" + filter.getStartDate() + "') and unix_timestamp( '" + getCurrentDateTime1() + "' )");
            sql.append("or ((operator_user = '" + filter.getName() + "' or res_user = '" + filter.getName() + "') and status = '1' and type = '2' and state = '1')");
        }
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        List result = query.list();
        BigInteger count = (BigInteger) result.get(0);
        return count;
    }

    public List<NodeNewschedules> queryNoPageByFilter(NodeNewschedulesFilter filter) {
        GenericQuery query = createQuery("obj");
        if (ObjectUtils.isNotBlank(filter.getType())) {
            query.append(" and obj.type =:type").setParam("type", filter.getType());
        }
        if (ObjectUtils.isNotBlank(filter.getState())) {
            query.append(" and obj.state =:state").setParam("state", filter.getState());
        }
        if (ObjectUtils.isNotBlank(filter.getStatus())) {
            query.append(" and obj.status =:status").setParam("status", filter.getStatus());
        }
        if (ObjectUtils.isNotBlank(filter.getResDept())) {
            query.append(" and obj.resDept like:resDept").setParam("resDept",
                    StringUtils.getLikewords(filter.getResDept()));
        }
        if (ObjectUtils.isNotBlank(filter.getResUser())) {
            query.append(" and obj.resUser like:resUser").setParam("resUser",
                    StringUtils.getLikewords(filter.getResUser()));
        }
        if (ObjectUtils.isNotBlank(filter.getResUserPhone())) {
            query.append(" and obj.resUserPhone =:resUserPhone").setParam("resUserPhone", filter.getResUserPhone());
        }
        if (ObjectUtils.isNotBlank(filter.getOperatorUser())) {
            query.append(" and obj.operatorUser like:operatorUser").setParam("operatorUser",
                    StringUtils.getLikewords(filter.getOperatorUser()));
        }
        if (ObjectUtils.isNotBlank(filter.getOperatorPhone())) {
            query.append(" and obj.operatorPhone =:operatorPhone").setParam("operatorPhone", filter.getOperatorPhone());
        }
        if (ObjectUtils.isNotBlank(filter.getNodeId())) {
            query.append(" and obj.nodeId =:nodeId").setParam("nodeId", filter.getNodeId());
        }
        if (ObjectUtils.isNotBlank(filter.getNodeIds())) {
            query.append(" and obj.nodeIds =:nodeIds").setParam("nodeIds", filter.getNodeIds());
        }
        if (ObjectUtils.isNotBlank(filter.getNodeName())) {
            query.append(" and obj.nodeName like:nodeName").setParam("nodeName",
                    StringUtils.getLikewords(filter.getNodeName()));
        }
        if (ObjectUtils.isNotBlank(filter.getNodeType())) {
            query.append(" and obj.nodeType =:nodeType").setParam("nodeType", filter.getNodeType());
        }
        if (ObjectUtils.isNotBlank(filter.getProjectId())) {
            query.append(" and obj.projectId =:projectId").setParam("projectId", filter.getProjectId());
        }
        if (ObjectUtils.isNotBlank(filter.getFactFinishDate())) {
            query.append(" and obj.factFinishDate >:factFinishDate").setParam("factFinishDate", filter.getFactFinishDate());
        }
        if (CollectionsUtils.isNotEmpty(filter.getProjectIds())) {
            query.append(" and obj.projectId in (:projectIds)");
            query.setParamList("projectIds", filter.getProjectIds());
        }
        query.setOrder("nodeId+0", BaseFilter.ASC);
        return query.listResult();
    }


    public List<NewProjects> queryProjectByAccraditation(NodeNewschedulesFilter filter) {
        StringBuffer sql = new StringBuffer();
        sql.append("" +
                "select DISTINCT p.sys_id as sysId,\n" +
                "p.create_date as createDate, \n" +
                "p.create_time as createTime,\n" +
                "p.create_user as createUser,\n" +
                "p.upd_date as updDate,\n" +
                "p.upd_time as updTime,\n" +
                "p.upd_user as updUser,\n" +
                "p.address as address,\n" +
                "p.contact_name as contactName,\n" +
                "p.contact_phone as contactPhone,\n" +
                "p.describes as describes,\n" +
                "p.industry_type as industryType,\n" +
                "p.money as money,\n" +
                "p.name as name,\n" +
                "p.nature_type as natureType,\n" +
                "p.project_type as projectType,\n" +
                "p.res_dept as resDept,\n" +
                "p.res_user as resUser,\n" +
                "p.sched_code as schedCode,\n" +
                "p.status as status,\n" +
                "p.user_id as userId,\n" +
                "p.owner_unit_person as ownerUnitPerson,\n" +
                "p.owner_unit_person_phone as ownerUnitPersonPhone,\n" +
                "p.project_classification as projectClassification,\n" +
                "p.fact_finish_date as factFinishDate,\n" +
                "p.plan_begin_date as planBeginDate,\n" +
                "p.res_phone as resPhone,\n" +
                "p.position as position,\n" +
                "p.nature_type_detail as natureTypeDetail,\n" +
                "p.occupy_dept as occupyDept,\n" +
                "p.occupy_operate_user as occupyOperateUser,\n" +
                "p.occupy_operate_user_phone as occupyOperateUserPhone,\n" +
                "p.occupy_res_user as occupyResUser,\n" +
                "p.occupy_res_user_phone as occupyResUserPhone,\n" +
                "p.group_code as groupCode,\n" +
                "p.group_name as groupName,\n" +
                "p.start_time as startTime \n" +
                " from t_bnp_new_project p inner join t_bnp_node_newschedule n\n" +
                "where p.sys_id = n.project_id ");
        if (StringUtils.isNotBlank(filter.getOperatorPhone())) {
            sql.append("and  n.operator_phone = '" + filter.getOperatorPhone() + "' ");
        }

        /*
        if (StringUtils.isNotBlank(filter.getResDept())) {
            sql.append("and  n.res_dept like '%" + filter.getResDept() + "%' ");
        }
        if (StringUtils.isNotBlank(filter.getOperatorUser())) {
            sql.append("and  n.operator_user = '" + filter.getOperatorUser() + "' ");
        }
        */
        if (filter.isResDept_th()) {
            sql.append("and  p.res_dept like '%" + filter.getType() + "%' ");
        }
        //搜索项目状态
        if (StringUtils.isNotBlank(filter.getStatus())) {
            if ("1".equals(filter.getStatus())) {
                //节点待审批部门确定
                sql.append("and n.state = '0'and p.status = '" + filter.getStatus() + "' ");
            } else {
                //
                sql.append("and  p.status > '1' ");
            }

        }
        //搜索项目名称
        if (StringUtils.isNotBlank(filter.getProjectName())) {
            sql.append("and  p.name like '%" + filter.getProjectName() + "%' ");
        }


        if (filter.getPaging() != null) {
            if (filter.getPaging().getSortCol() == null || "".equals(filter.getPaging().getSortCol())) {
                sql.append(" ORDER BY  p.status+0 asc,n.state+0 asc");
            }
        }
        String hql = sql.toString();
        hql = new StringBuffer(" select count(1) ").append(" from ( ")
                .append(hql).append(" ) temp ").toString();
        Query getCount = getSession().createSQLQuery(hql);
        if (filter.getPaging() != null) {
            int count = ((Number) getCount.uniqueResult()).intValue();
            int resultSize = count;
            int size = filter.getPaging().getPageSize();
            int page = filter.getPaging().getCurrentPage();
            int MaxPage = resultSize / size;
            if (!(resultSize % size == 0)) {
                MaxPage = (resultSize / size) + 1;
            }
            if (page > MaxPage) {
                filter.getPaging().setCurrentPage(MaxPage);
            }
            filter.getPaging().setRecords(resultSize);
        }

        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(NewProjects.class));
        if (filter.getPaging() != null) {
            query.setFirstResult(filter.getPaging().getStartRow());
            query.setMaxResults(filter.getPaging().getPageSize());
        }
        List<NewProjects> result = query.list();
        return result;
    }


    public List<NodeNewschedules> queryNoStateNode(String projectId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId =:projectId").setParam("projectId", projectId);
        query.append(" and obj.state = '0'");
        return query.listResult();
    }


    public int queryFinishNodesNumInWeek() {
        StringBuffer sql = new StringBuffer();
        sql.append("select * " +
                "from t_bnp_node_newschedule " +
                "where type = '2' " +
                "and status = '2' " +
                "and fact_finish_date >= replace(date_sub(current_date(),interval 15 day),'-','.')");
        //后面改成7天
        String hql = sql.toString();
        hql = new StringBuffer(" select count(1) ").append(" from ( ")
                .append(hql).append(" ) temp ").toString();
        Query getCount = getSession().createSQLQuery(hql);
        int count = ((Number) getCount.uniqueResult()).intValue();
        return count;
    }

    public List<PlanStartScheduleDto> queryPlanStartSchedule() {
        StringBuffer sql = new StringBuffer();
        sql.append("select substr(start_time,1,7) dataTime,sum(1) count " +
                "from t_bnp_new_project group by dataTime order by dataTime asc");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        List list = query.list();
        PlanStartScheduleDto dto = null;
        List<PlanStartScheduleDto> result = new ArrayList<>();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Object[] obj = (Object[]) it.next();
            dto = new PlanStartScheduleDto();
            if(ObjectUtils.isNotBlank(obj[0])){
                dto.setDataTime(obj[0].toString());
            }else{
                dto.setDataTime("");
            }
            if(ObjectUtils.isNotBlank(obj[1])){
                dto.setCount((BigDecimal) obj[1]);
            }else{
                dto.setCount(BigDecimal.valueOf(0));
            }
            result.add(dto);
        }
        return result;
    }

    public List<PlanStartScheduleDto> queryFactStartSchedule() {
        StringBuffer sql = new StringBuffer();
        sql.append("select substr(fact_finish_date,1,7) dataTime,sum(1) count " +
                "from t_bnp_new_project where status = '4' group by dataTime order by dataTime asc");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        List list = query.list();
        PlanStartScheduleDto dto = null;
        List<PlanStartScheduleDto> result = new ArrayList<>();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Object[] obj = (Object[]) it.next();
            dto = new PlanStartScheduleDto();
            if(ObjectUtils.isNotBlank(obj[0])){
                dto.setDataTime(obj[0].toString());
            }else{
                dto.setDataTime("");
            }
            if(ObjectUtils.isNotBlank(obj[1])){
                dto.setCount((BigDecimal) obj[1]);
            }else{
                dto.setCount(BigDecimal.valueOf(0));
            }
            result.add(dto);
        }
        return result;
    }

    //根据项目id查询项目剩余的节点
    public List<NodeNewschedules> querySurplusNodesListByProjectId(NewProjectsFilter filter){
        GenericQuery query = createQuery("obj");
        if (ObjectUtils.isNotBlank(filter.getSysId())) {
            query.append(" and obj.projectId =:projectId").setParam("projectId", filter.getSysId());
        }
        //大节点
        query.append(" and obj.status !=:status").setParam("status", "2");
        query.append(" and obj.state =:state").setParam("state", "1");
        query.append(" and obj.type =:type").setParam("type", "1");
        return query.listResult();
    }

}
